package org.subside.MQ.rabbitmq.RoutingModel;

import com.rabbitmq.client.*;
import org.subside.MQ.rabbitmq.config.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ProductorRouting {
 
    private static final String EXCHANGE_NAME = "exchange_routing";
 
    private static final String ROUTINGKEY_ERROR = "errorKey";
 
    private static final String ROUTINGKEY_RIGHT = "rightKey";
 
    public static void main(String[] args) throws Exception {
        Connection connection =  ConnectionUtil.getConnection();
        Channel channel = null;
        try {
            channel = connection.createChannel();
            channel.basicPublish(EXCHANGE_NAME, ROUTINGKEY_ERROR, null, "hello world error".getBytes("UTF-8"));
            channel.basicPublish(EXCHANGE_NAME, ROUTINGKEY_RIGHT, null, "hello world right".getBytes("UTF-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                channel.close();
                connection.close();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (TimeoutException e) {
                e.printStackTrace();
            }
        }
    }
}